package com.rjs.nio.channel;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * 传输文件
 * @author LiuZhenghua
 * 2017年12月8日 下午2:01:11
 */
public class TransferDemo {

	public static void main(String[] args) throws IOException {
		RandomAccessFile fromFile = new RandomAccessFile("src/test/resources/nio-buffer.txt", "r");
		FileChannel fromChannel = fromFile.getChannel();
		RandomAccessFile toFile = new RandomAccessFile("src/test/resources/nio-buffer-new.txt", "rw");
		FileChannel toChannel = toFile.getChannel();
		
//		fromChannel.transferTo(0, fromChannel.size(), toChannel);
		toChannel.transferFrom(fromChannel, 0, fromChannel.size());
		fromFile.close();
		toFile.close();
	}
}
